/*
 * Created by Jaren at 2021/10/29 11:38
 */
import 'package:binary/binary.dart';
import 'package:inmotion_protocol/util/byte_util.dart';

class Version {
    static const singleVersionLength = 4;

  Uint8 device = Uint8.zero;
  String appVersion = '';
  String blVersion = '';
  String hwVersion = '';

  Version(this.device, this.appVersion, this.blVersion, this.hwVersion);

  @override
  String toString() {
    return "[device: 0x" + ByteUtil.byte2Hex(device.value) + ", app: $appVersion, bootloader: $blVersion, hw: $hwVersion]";
  }
}

class VersionWrapper {
    Map<int, Version> versions = {};

    Version? getByDevice(int device) {
        if (!versions.containsKey(device)) return null;
        return versions[device];
    }

    String getAppVersionByDevice(int device) {
        if (!versions.containsKey(device)) return '';
        return versions[device]!.appVersion;
    }

    void put(int device, Version v) {
        versions[device] = v;
    }

    @override
    String toString() {
        return versions.toString();
    }
}